﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BKH.BLL
{
    class NhaCungCapBUO:IBUO<tbl_NhaCungCap>
    {

        HospitalDBDataContext context = new HospitalDBDataContext();
        public bool Insert(tbl_NhaCungCap obj)
        {

            try
            {
                context.tbl_NhaCungCaps.InsertOnSubmit(obj);
                context.SubmitChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }
        }

        public bool Delete(int id)
        {
            try
            {
                tbl_NhaCungCap obj = context.tbl_NhaCungCaps.Where(n => n.NhaCungCapID == id).ToList<tbl_NhaCungCap>().FirstOrDefault();

                context.tbl_NhaCungCaps.DeleteOnSubmit(obj);
                context.SubmitChanges();
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }

        public bool Delete(tbl_NhaCungCap obj)
        {
            throw new NotImplementedException();
        }

        public List<tbl_NhaCungCap> GetAll()
        {
            return context.tbl_NhaCungCaps.ToList<tbl_NhaCungCap>();
        }

        public tbl_NhaCungCap GetSingle(int id)
        {
            throw new NotImplementedException();
        }

        public bool Update(int id, tbl_NhaCungCap obj)
        {
            try
            {
                tbl_NhaCungCap objs = context.tbl_NhaCungCaps.Where(n => n.NhaCungCapID == id).ToList<tbl_NhaCungCap>().FirstOrDefault();
                objs.Name = obj.Name;
                objs.Tel = obj.Tel;
                objs.Address = objs.Address;
                context.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
            
        }
    }
}
